import java.util.HashMap;
import java.util.Set;


public class Board<T> {
	
	HashMap<CoordinatePair, T> mMap;
	
	public Board(int[][] map) {
	    mMap = new HashMap<CoordinatePair, T>();
	    setMapCoordinates(map);
	}
	
	/**
	 * Here we set the available coordinates of the map. The map should only
	 * be changed in this method.
	 */
	private void setMapCoordinates(int[][] map) {
	    for(int[] pair : map) {
            mMap.put(new CoordinatePair(pair), null);
        }
	}
	
	public int[][] getMapCoordinates() {
	    Set<CoordinatePair> keys = mMap.keySet();
        int[][] coords = new int[keys.size()][];
        int i = 0;
        for(CoordinatePair c : keys) {
            coords[i] = c.coordinates;
            i++;
        }
        return coords;
	}
	
	public T get(int[] coordinates) {
	    return mMap.get(new CoordinatePair(coordinates));
	}
	
	void put(int[] coordinates, T object) {
	    mMap.put(new CoordinatePair(coordinates), object);
	}
	
	void remove(int[] coordinates) {
	    mMap.put(new CoordinatePair(coordinates), null);
	}
	
	public boolean isValid(int[] coords) {
	    return mMap.containsKey(new CoordinatePair(coords));
	}

	private class CoordinatePair {
	    public CoordinatePair(int[] coords) {
	        coordinates = coords;
	        
	        q = coords[0];
	        r = coords[1];
	    }
	    
	    public int[] coordinates;
	    public int q;
	    public int r;
	    
	    public boolean equals(Object o) {
	        return ((CoordinatePair) o).q == q && ((CoordinatePair) o).r == r;
	    }
	    
	    public int hashCode() {
	        return q * 10 + r * 10;
	    }
	}
}
